<?php
// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $


/**
 * Declare the available regions implemented by this engine.
 *
 * @return
 *  An array of regions. The first array element will be used as the default region for themes.
 */
function abstruct_regions() {
  return array(
       // common page regions
       'content' => t('content'),
       'metabar' => t('metabar block'),
       'title' => t('title block'),
       'navbar' => t('navbar'),
       'sidebar' => t('sidebar'),
       'page_footer' => t('footer'),
       
       // front page
       'front_feed_list' => t('front page aggregator headlines'),
       'front_upper_menu' => t('menu in upper left of front page'),
  );
}


/**
   * This snippet catches the default login form and looks for an
   * user_login.tpl.php file in the theme folder
   * source: http://drupal.org/node/19855
   */

function phptemplate_user_login($form) {
    return _phptemplate_callback('block-login', array('form' => $form));
}


/**
   * This snippet returns a link reflecting the login status for a user -- for
   * use with sites having a separate login page
   */

function phptemplate_user_login_status() {
  global $user;
  $login_status = '';
  $link = '';
  $class = 'login';
  
  if ( $user->uid )
  {
    $link = l("log out","logout");
    $class = 'in';
  }
  else
  {
    $link =  l("login","user");
    $class = 'out';
  }
  
  $login_status = '<div id="login_status" class="{$class}">' . $link . '</div>';

  return $login_status;
}


/**
 * Sets the body-tag class attribute.
 *
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
 */
function phptemplate_body_class($sidebar_left, $sidebar_right) {
  if ($sidebar_left != '' && $sidebar_right != '') {
    $class = 'sidebars';
  }
  else {
    if ($sidebar_left != '') {
      $class = 'sidebar-left';
    }
    if ($sidebar_right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' &raquo; ', $breadcrumb) .'</div>';
  }
}

/**
 * Allow themable wrapping of all comments.
 */
function phptemplate_comment_wrapper($content, $type = null) {
  static $node_type;
  if (isset($type)) $node_type = $type;

  if (!$content || $node_type == 'forum') {
    return '<div id="comments">'. $content . '</div>';
  }
  else {
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
  }
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function _phptemplate_variables($hook, $vars = array()) {

  if ($hook == 'page') {
  
    // separate login box (see http://drupal.org/node/52389)
    global $user;
    if (arg(0) == 'user') {
      if ($user->uid == 0) {
        $vars['template_file'] = 'page-login';
      }
      elseif (arg(1) == 'login' || arg(1) == 'register' || arg(1) == 'password' ) {
        $vars['template_file'] = 'page-login';
      }
    }
  
    // add secondary menu
    if ($secondary = menu_secondary_local_tasks()) {
      $output = '<span class="clear"></span>';
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
      $vars['tabs2'] = $output;
    }

    // Hook into color.module (disabled
    #if (module_exists('color')) _color_page_alter($vars);
    
    return $vars;
  }
  return array();
}

/**
 * Returns the rendered local tasks. The default implementation renders
 * them as tabs.
 *
 * @ingroup themeable
 */
function phptemplate_menu_local_tasks() {
  $output = '';

  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
  }

  return $output;
}
